﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LIM.model;

namespace LIM.controller
{
    public class DanhMucHeThongController : BaseController
    {
        public DanhMucHeThongController()
        { 
        }
        //LIMS_Entities db = new LIMS_Entities();
        public tbl_DanhMuc_HeThong LoadDM_HeThuong(int ID)
        {
            return LIMS_Entities.tbl_DanhMuc_HeThong.Where(p => p.RowID == ID).FirstOrDefault(); 
        }
        public List<tbl_DanhMuc_HeThong> LoadData()
        {
            return LIMS_Entities.tbl_DanhMuc_HeThong.OrderBy(p => p.ThuTu).ToList();
        }
        public List<tbl_DanhMuc_HeThong> Find(string abc)
        {
            return LIMS_Entities.tbl_DanhMuc_HeThong.ToList().Where(p => p.MaDanhMuc.ToUpper().Contains(abc.ToUpper()) || p.TenGoi.ToUpper().Contains(abc.ToUpper())).OrderBy(p => p.ThuTu).ToList();
        }
        public List<tbl_DanhMuc_HeThong> LoadDataParent()
        {
            return LIMS_Entities.tbl_DanhMuc_HeThong.Where(p => p.RowIDParent == null).OrderBy(p=>p.ThuTu).ToList();
        }
        public List<tbl_DanhMuc_HeThong> LoadDataChild(int ParentID)
        {
            return LIMS_Entities.tbl_DanhMuc_HeThong.Where(p => p.RowIDParent == ParentID).OrderBy(p => p.ThuTu).ToList();
        }
        public List<tbl_DanhMuc_HeThong> LoadDataChild(string MaDanhMucCha)
        {
            return LIMS_Entities.tbl_DanhMuc_HeThong.Where(d => d.tbl_DanhMuc_HeThong2.MaDanhMuc == MaDanhMucCha).ToList();
        }
        public List<tbl_DanhMuc_HeThong> FindInList(List<tbl_DanhMuc_HeThong> lst,string TextSearch)
        { 
            return lst.Where(p=>p.TenGoi.ToUpper().Contains(TextSearch.ToUpper())).ToList();
        }
        public bool Save(bool IsADD,tbl_DanhMuc_HeThong dm)
        {
            bool Result = false;
            try
            {
                if (IsADD == true)
                {
                    LIMS_Entities.AddTotbl_DanhMuc_HeThong(dm);
                }
                LIMS_Entities.SaveChanges();
                Result = true;
            }
            catch (Exception)
            {
                Result = false;
            }
            return Result;
        }
    }
}
